package com.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.model.auto.PreferenceChoice;
import com.service.IPreferenceChoiceService;
import com.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2022-09-14
 */
@RestController
@RequestMapping("/preferenceChoice")
public class PreferenceChoiceController{
    @Autowired
    private IPreferenceChoiceService preferenceChoiceService;

    @GetMapping("/getPreferenceChoice")
    public R getPreferenceChoice(String stuId) {
        PreferenceChoice preferenceChoice = preferenceChoiceService.getOne(new LambdaQueryWrapper<PreferenceChoice>()
                .eq(PreferenceChoice::getStuId, stuId));
        return R.ok(preferenceChoice);
    }

    @PostMapping("SaveOrUpdatePreferenceChoice")
    public R SaveOrUpdatePreferenceChoice(@RequestBody PreferenceChoice PreferenceChoice) {
        boolean result = preferenceChoiceService.saveOrUpdate(PreferenceChoice);
        if (!result) {
            return R.error();
        }
        return R.ok();
    }
}
